package com.lsh.quartz.job;

import com.lsh.service.SetmealService;
import com.lsh.utils.QiNiuUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.io.Serializable;
import java.util.List;

public class Job extends QuartzJobBean implements Serializable {
    @Autowired
    private SetmealService setmealService;
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //查询七牛所有图片名称
        List<String> qiniuName = QiNiuUtils.getAllImgName();
        //查询数据库所有图片名
        List<String> dbName = setmealService.findAllImgName();
        qiniuName.removeAll(dbName);
        String[] strings = qiniuName.toArray(new String[]{});
        //调用七牛云工具类里面的批量删除
        List<String> removeName = QiNiuUtils.removeFiles(strings);
        System.out.println(removeName);
    }
}
